package com.liuxu.topnews.utils;

import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class TimeUtil {
    private static final SimpleDateFormat EN;
    public static final String FORMAT_DATE_CN = "yyyy年MM月dd日";
    public static final String FORMAT_DATE_EN = "yyyy-MM-dd";
    public static final String FORMAT_DAY_CN = "HH时mm分ss秒";
    public static final String FORMAT_DAY_CN_2 = "HH时mm分";
    public static final String FORMAT_DAY_EN = "HH:mm:ss";
    public static final String FORMAT_DAY_EN_2 = "HH:mm";
    public static final String FORMAT_DAY_EN_3 = "mm:ss";
    public static final String FORMAT_TIME_CN = "yyyy年MM月dd HH时mm分ss秒";
    public static final String FORMAT_TIME_CN_2 = "yyyy年MM月dd HH时mm分";
    public static final String FORMAT_TIME_EN = "yyyy-MM-dd HH:mm:ss";
    public static final String FORMAT_TIME_EN_2 = "yyyy-MM-dd HH:mm";
    private static final SimpleDateFormat SDF;
    private static final String TAG = "TimeUtil";
    public static final int TIME_AFTER = 3;
    public static final int TIME_BEFORE = 1;
    public static final int TIME_ING = 2;

    static {
        SDF = new SimpleDateFormat("yyyy年MM月dd HH时mm分ss秒", Locale.CHINA);
        EN = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    }

    public TimeUtil() {
    }

    public static int betweenTime(long var0, long var2, long var4) {
        long var8 = var2;
        long var6 = var4;
        if (var2 > var4) {
            var6 = var2;
            var8 = var4;
        }

        if (var8 > var0) {
            return 1;
        } else {
            return var6 < var0 ? 3 : 2;
        }
    }

    private static String converToWeek(int var0) {
        switch(var0) {
            case 1:
                return "星期日";
            case 2:
                return "星期一";
            case 3:
                return "星期二";
            case 4:
                return "星期三";
            case 5:
                return "星期四";
            case 6:
                return "星期五";
            case 7:
                return "星期六";
            default:
                return null;
        }
    }

    public static String convertDayOfWeek(String var0, long var1) {
        Calendar var9 = Calendar.getInstance();
        var9.setTime(new Date(var1));
        int var3 = var9.get(1);
        int var4 = var9.get(2);
        int var5 = var9.get(5);
        int var6 = var9.get(11);
        String var7;
        if (var6 > 9) {
            var7 = String.valueOf(var6);
        } else {
            var7 = "0" + var6;
        }

        var6 = var9.get(12);
        String var8;
        if (var6 > 9) {
            var8 = String.valueOf(var6);
        } else {
            var8 = "0" + var6;
        }

        return String.format(Locale.getDefault(), var0, var3, var4 + 1, var5, var7, var8, converToWeek(var9.get(7)));
    }

    public static String convertTime(String var0, long var1) {
        try {
            Date var3 = new Date();
            var3.setTime(var1);
            var0 = format(var0, var3);
            return var0;
        } catch (IllegalArgumentException var4) {
            Log.e("TimeUtil", var4.getMessage());
            return "";
        }
    }

    public static String convertToDifftime(String var0, long var1) {
        Date var3 = new Date(var1);
        SDF.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        SDF.applyPattern(var0);
        return SDF.format(var3);
    }

    public static String convertToTime(long var0) {
        return convertToTime("yyyy-MM-dd HH:mm:ss", var0);
    }

    public static String convertToTime(String var0, long var1) {
        return convertToTime(var0, new Date(var1));
    }

    public static String convertToTime(String var0, Calendar var1) {
        return format(var0, var1.getTime());
    }

    public static String convertToTime(String var0, Date var1) {
        return format(var0, var1);
    }

    public static long covertToLong(String var0, String var1) {
        try {
            long var2 = SDF.parse(var1).getTime();
            return var2;
        } catch (ParseException var4) {
            Log.e("TimeUtil", var4.getMessage());
            return -1L;
        }
    }

    private static String format(String var0, Date var1) {
        SDF.setTimeZone(TimeZone.getDefault());
        SDF.applyPattern(var0);
        return SDF.format(var1);
    }

    public static String getCurTimeFormat() {
        Date var0 = new Date(System.currentTimeMillis());
        return EN.format(var0);
    }

    public static String getLookTime(long var0) {
        var0 /= 1000L;
        long var2 = var0 / 3600L;
        long var4 = var0 / 60L - var2 * 60L;
        return var2 + "时" + var4 + "分" + (var0 - var2 * 60L * 60L - var4 * 60L) + "秒";
    }

    public static String intervalAfterTime(long var0) {
        var0 = (var0 - System.currentTimeMillis()) / 1000L;
        if (var0 <= 60L) {
            return "刚刚";
        } else {
            StringBuilder var3;
            if (var0 < 3600L) {
                var3 = new StringBuilder();
                if (var0 / 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 /= 60L;
                }

                return var3.append(var0).append("分钟后").toString();
            } else if (var0 < 86400L) {
                var3 = new StringBuilder();
                if (var0 / 60L * 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 /= 3600L;
                }

                return var3.append(var0).append("小时后").toString();
            } else if (var0 < 2592000L) {
                var3 = new StringBuilder();
                if (var0 / 24L * 60L * 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 /= 86400L;
                }

                return var3.append(var0).append("天后").toString();
            } else if (var0 < 31104000L) {
                var3 = new StringBuilder();
                if (var0 / 30L * 24L * 60L * 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 /= 2592000L;
                }

                return var3.append(var0).append("月后").toString();
            } else if (var0 < 31104000L) {
                var3 = new StringBuilder();
                if (var0 / 12L * 30L * 24L * 60L * 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 /= 31104000L;
                }

                return var3.append(var0).append("年后").toString();
            } else {
                Date var2 = new Date();
                var2.setTime(var0);
                return format("yyyy年MM月dd日", var2);
            }
        }
    }

    public static String intervalTime(long var0) {
        return intervalTime(var0, false);
    }

    public static String intervalTime(long var0, boolean var2) {
        long var3 = (System.currentTimeMillis() - var0) / 1000L;
        if (var2 && var3 < 0L) {
            return intervalAfterTime(var0);
        } else if (var3 <= 60L) {
            return "刚刚";
        } else {
            StringBuilder var6;
            if (var3 < 3600L) {
                var6 = new StringBuilder();
                if (var3 / 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 = var3 / 60L;
                }

                return var6.append(var0).append("分钟前").toString();
            } else if (var3 < 86400L) {
                var6 = new StringBuilder();
                if (var3 / 60L * 60L == 0L) {
                    var0 = 1L;
                } else {
                    var0 = var3 / 3600L;
                }

                return var6.append(var0).append("小时前").toString();
            } else if (var3 < 2592000L) {
                return var3 / 24L * 60L * 60L == 0L ? "昨天" : var3 / 86400L + "天前";
            } else {
                Date var5 = new Date();
                var5.setTime(var0);
                return format("yyyy年MM月dd日", var5);
            }
        }
    }
}

